package com.example.cpms.controller;

import com.example.cpms.entity.Building;
import com.example.cpms.entity.Propety;
import com.example.cpms.service.BuildingService;
import com.example.cpms.service.PropetyService;
import com.example.cpms.utils.PageBean;
import com.example.cpms.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController
public class PropetyController {

    @Autowired
    private PropetyService propetyService;

    /**
     * 物业费分页查询
     * @param page
     * @param pageSize
     * @param username
     * @param buildingname
     * @return
     */
    @GetMapping("/park/propertyfee")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10")Integer pageSize,
                       String username,String buildingname){
        log.info("物业费分页查询：{}，{},{}",page,pageSize,username,buildingname);
        PageBean pageBean = propetyService.page(page,pageSize,username,buildingname);
        return Result.success(pageBean);
    }


    /**
     * 物业费删除
     * @param id
     * @return
     */
    @DeleteMapping("/park/propertyfee/{id}")
    public Result delete(@PathVariable Integer id){
            log.info("物业费删除:{}",id);
            propetyService.delete(id);
            return Result.success();
    }


    /**
     * 新增物业费账单
     * @param propety
     * @return
     */
    @PostMapping("/park/propertyfee")
    public Result insert(@RequestBody Propety propety){
        log.info("新增物业费账单：{}",propety);
        propetyService.add(propety);
        return Result.success();
    }

    /**
     * 编辑物业费信息
     * @param propety
     * @return
     */
    @PutMapping("/park/propertyfee")
    public Result updata(@RequestBody Propety propety){
        log.info("编辑楼宇：{}",propety);
        propetyService.update(propety);
        return Result.success();
    }

}
